var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function i() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (i.prototype = e.prototype, 
    new i());
}), a = this && this.__decorate || function(t, e, o, i) {
    var s, a = arguments.length, n = a < 3 ? e : null === i ? i = Object.getOwnPropertyDescriptor(e, o) : i;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) n = Reflect.decorate(t, e, o, i); else for (var c = t.length - 1; 0 <= c; c--) (s = t[c]) && (n = (a < 3 ? s(n) : 3 < a ? s(e, o, n) : s(e, o)) || n);
    return 3 < a && n && Object.defineProperty(e, o, n), n;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameData"), s = e("DataManager"), c = e("EggsManager"), l = e("LoadManager"), d = e("UIManager"), u = e("WebManager"), p = e("Global"), h = e("NewActivityEggsView"), f = cc._decorator, g = f.ccclass, m = (f.property, 
function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.data = {
            id: 21,
            type: h.NewActivityEggType.CLICK,
            num: 1,
            options: {}
        }, t.type = h.NewActivityEggType.CLICK, t.count = 0, t.btnNode = null, t.isExe = !1, 
        t;
    }
    return i(t, e), t.prototype.start = function() {}, t.prototype.init = function(t) {
        this.type = t.type, (this.data = t).options.pos && this.node.setPosition(t.options.pos), 
        t.options.size && this.node.setContentSize(t.options.size), this.addEvent();
    }, t.prototype.addEvent = function() {
        switch (this.data.options.personIdx && cc.systemEvent.on("refresh_person_skin", this.refreshCallback, this), 
        GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) && !r.GD.isFollow && this.node.on("follow_success", this.doReward, this), 
        this.data.type) {
          case h.NewActivityEggType.CLICK:
            this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this);
            break;

          case h.NewActivityEggType.DEALY:
            this.node.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), 
            this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this);
            break;

          case h.NewActivityEggType.MOVE:
            this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this);
            break;

          case h.NewActivityEggType.COMPLEX:
            this.node.on(cc.Node.EventType.TOUCH_START, this.touchStartHandler, this), this.node.on(cc.Node.EventType.TOUCH_MOVE, this.touchMoveHandler, this), 
            this.node.on(cc.Node.EventType.TOUCH_END, this.touchEndHandler, this), this.node.on(cc.Node.EventType.TOUCH_CANCEL, this.touchEndHandler, this), 
            this.btnNode = new cc.Node(), this.data.options.path && l.default.getInstance().loadSpriteFrame({
                url: this.data.options.path,
                sprite: this.btnNode.addComponent(cc.Sprite)
            }), this.data.options.scale && (this.btnNode.scale = this.data.options.scale), this.data.options.pos && (this.data.options.offect ? this.btnNode.setPosition(this.data.options.pos.add(this.data.options.offect)) : this.btnNode.setPosition(this.data.options.pos)), 
            this.data.options.target ? (this.btnNode.zIndex = -1, this.btnNode.parent = this.data.options.target.parent) : this.btnNode.parent = this.node;
        }
    }, t.prototype.removeEvent = function() {
        cc.systemEvent.targetOff(this), this.node.targetOff(this);
    }, t.prototype.touchStartHandler = function(t) {
        switch (this.data.type) {
          case h.NewActivityEggType.CLICK:
            break;

          case h.NewActivityEggType.DEALY:
            this.scheduleOnce(this.callback, this.data.num);
            break;

          case h.NewActivityEggType.MOVE:
            break;

          case h.NewActivityEggType.COMPLEX:
            var e, o = t.getLocation();
            this.data.options.target ? (e = this.data.options.target.convertToNodeSpaceAR(o), 
            Math.abs(e.x) <= this.data.options.target.width / 2 && Math.abs(e.y) <= this.data.options.target.height / 2 && this.scheduleOnce(this.delayCallback, this.data.num)) : (e = this.btnNode.convertToNodeSpaceAR(o), 
            Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (this.count = 1));
        }
    }, t.prototype.touchMoveHandler = function(t) {
        switch (this.data.type) {
          case h.NewActivityEggType.CLICK:
            break;

          case h.NewActivityEggType.MOVE:
            30 < t.getPreviousLocation().sub(t.getLocation()).mag() && (this.count < this.data.num && this.count++, 
            this.count == this.data.num && this.callback());
            break;

          case h.NewActivityEggType.COMPLEX:
            0 < this.count && (this.data.options.target ? this.data.options.target.setPosition(this.data.options.target.parent.convertToNodeSpaceAR(t.getLocation())) : this.btnNode.setPosition(this.btnNode.parent.convertToNodeSpaceAR(t.getLocation())));
        }
    }, t.prototype.touchEndHandler = function(t) {
        switch (this.data.type) {
          case h.NewActivityEggType.CLICK:
            this.count < this.data.num && this.count++, this.count == this.data.num && this.callback();
            break;

          case h.NewActivityEggType.DEALY:
            this.unschedule(this.callback);
            break;

          case h.NewActivityEggType.MOVE:
            break;

          case h.NewActivityEggType.COMPLEX:
            var e, o, i;
            this.data.options.target ? (this.unschedule(this.delayCallback), 1 == this.count ? this.count = 0 : (o = t.getLocation(), 
            e = this.btnNode.convertToNodeSpaceAR(o), Math.abs(e.x) <= this.btnNode.width / 2 && Math.abs(e.y) <= this.btnNode.height / 2 && (i = this.data.options.scale || 1, 
            cc.tween(this.btnNode).to(.1, {
                scale: 1.1 * i
            }).to(.1, {
                scale: +i
            }).start(), this.callback(), this.data.options.target.setPosition(this.data.options.pos), 
            this.btnNode.destroy(), this.btnNode = null))) : (1 == this.count && (this.count = 0), 
            o = this.btnNode.convertToWorldSpaceAR(cc.Vec2.ZERO), i = this.data.options.personView.node.convertToWorldSpaceAR(cc.Vec2.ZERO), 
            50 <= o.y - i.y && o.y - i.y <= 150 && Math.abs(o.x - i.x) < 100 && (cc.tween(this.btnNode).to(.1, {
                scale: 1.1
            }).to(.1, {
                scale: 1
            }).start(), this.callback(), this.btnNode.destroy(), this.btnNode = null));
        }
    }, t.prototype.refreshCallback = function() {
        this.data.options.personView && this.data.options.personView.personIdx == this.data.options.personIdx && -1 == c.default.getInstance().checkEggPerson(this.data.id) ? this.node.active = !0 : this.node.active = !1;
    }, t.prototype.delayCallback = function() {
        this.count = 1;
    }, t.prototype.callback = function() {
        var e = this;
        this.isExe || (this.isExe = !0, this.data.type == h.NewActivityEggType.MOVE ? (this.removeEvent(), 
        this.isExe = !1, this.data.type = h.NewActivityEggType.COMPLEX, this.addEvent()) : -1 == c.default.getInstance().checkEggPerson(this.data.id) && (!GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) || r.GD.isFollow ? this.doReward() : d.default.getInstance().loadPnl("eggsTips").then(function(t) {
            t && (t.target = e.node), e.isExe = !1;
        })));
    }, t.prototype.doReward = function() {
        var t = this;
        u.default.getInstance().sentLog("获得皮肤彩蛋id:" + this.data.id), cc.warn(this.data, this.count), 
        this.node.on("egg_get", this.doGet, this), d.default.getInstance().loadPopPnl("egg_get", {
            type: p.RewardType.SKIN,
            idx: this.data.id,
            target: this.node,
            success: function() {
                t.isExe = !1;
            }
        });
    }, t.prototype.doGet = function() {
        this.removeEvent(), c.default.getInstance().updateEggPerson(this.data.id), r.GD.personIdx = -1 - this.data.id, 
        r.GD.eggsHintState = 1, s.default.getInstance().save(), this.node.off("egg_get"), 
        d.default.getInstance().hideAllPnl(), d.default.getInstance().showPnl("start");
    }, a([ g ], t);
}(cc.Component));

n.default = m;